﻿using System;
using blackhouse.IdentityCms.Data;

namespace blackhouse.IdentityCms.Tests.FakeDbContexts {
    internal class TestDbContexts {

        internal FakeSiteDbContext SiteDbContext;
        internal FakePageDbContext PageDbContext;
        internal FakeTemplateDbContext TemplateDbContext;

        internal const int ExampleSiteId = 1;
        internal const string ExampleSiteName = "My Example Site";
        internal const string ExampleSiteName2 = "My Profesional Site";

        internal const string ExamplePageName = "My Example Page";
        internal const string ExamplePageName2 = "My Profesional Page";

        internal void InitializeSiteDbContext() {
            this.SiteDbContext = new FakeSiteDbContext();
            FakeSiteDbContext.Reset();
            DbFactory.SetSiteDbContext(typeof(FakeSiteDbContext));
        }

        internal void InitializePageDbContext() {
            this.PageDbContext = new FakePageDbContext();
            PageDbContext.Reset();
            DbFactory.SetPageDbContext(typeof(FakePageDbContext));
        }

        internal void InitializeTemplateDbContext() {
            this.TemplateDbContext = new FakeTemplateDbContext();
            this.TemplateDbContext.Reset();
            DbFactory.SetTemplateDbContext(typeof(FakeTemplateDbContext));
        }

        internal void AddExampleSite(int siteId = ExampleSiteId, string siteName = ExampleSiteName) {
            this.SiteDbContext.Sites.Add(new SiteData { Id = siteId, Name = siteName });
        }

        internal void AddExamplePage(int siteId = ExampleSiteId, string pageName = ExamplePageName) {
            this.PageDbContext.Pages.Add(new PageData { Id = this.PageDbContext.Pages.Count + 1, SiteId = siteId, Name = pageName, SiteCulture = String.Empty });
        }

        internal void AddExampleTemplate(string templateName, string templateDescription) {
            this.TemplateDbContext.Templates.Add(new TemplateData
            {
                Id = this.TemplateDbContext.Templates.Count + 1,
                Name = templateName,
                Description = templateDescription
            });
        }

    }
}
